<template>
	<!-- 主体信息 -->
	<view>
		<view class="main_title">
			<text>主体类别</text>
			<text>{{subject}}</text>
		</view>
		<view class="main_title">
			<text>是否存在</text>
			<u-switch v-model="showvalue" @change="changeVal" size="28"></u-switch>
		</view>
		<!-- 表单 -->
		<view class="mainNumber" v-show="showvalue">
			<view class="archives-form-item">
				<view>主体数量</view>
			</view>

			<u-form-item v-for="(item, index) in personList" :key="index" borderBottom>
				<u-checkbox-group placement="column">
					<u-checkbox :label="item.name" :name="item.name" @change="changeBox(item,index)">
					</u-checkbox>
				</u-checkbox-group>
				<view class="num_list">
					<text class="num_text">数量：</text>
					<u-input placeholder="请输入数量" v-model="arr[index].num" type="number"></u-input>
				</view>
			</u-form-item>
			<!-- <button @click="sum">核算</button> -->
		</view>
	</view>
</template>

<script>
	import {
		jsonParIfy
	} from "@/static/js/uilt/index.js"
	export default {
		name: "mineForm",
		props: {
			showValue: {
				type: Boolean,
				default: false
			},
			personList: {
				type: Array,
				default: () => {
					return []
				}
			},
			subject: {
				type: String,
				default: ''
			},
			typeBody: {
				type: Number,
				// default:0
			}
		},
		data() {
			return {
				showvalue: false,
				arr: [],
				listData: []
			};
		},
		watch: {
			personList: {
				deep: true,
				immediate: true,
				handler(newVal) {
					newVal.forEach(e => {
						this.arr.push({})
					})
					//console.log(newVal, "99777777777777");
				}
			}
		},
		methods: {
			sum() {
				let nums = jsonParIfy(this.arr)
				let obj = {
					muns: 0,
					id: new Array
				}
				nums.forEach(e => {
					if (Object.keys(e).length !== 0) {
						obj.muns += parseInt(e.num)
						obj.id.push(e.id)
					}
				})
				obj = {
					...obj,
					type: this.typeBody
				}
				obj.id = obj.id.toString()
				//console.log(obj);
				return jsonParIfy(obj)
			},
			changeBox(item, i) {
				item = jsonParIfy(item)
				item.disabled = !item.disabled
				this.personList.id = 55555555
				//console.log(item, "33333333333333");
				if (item.disabled) {
					this.arr[i] = jsonParIfy(item)
				} else {
					this.arr.splice(i, 1, {})
				}
			},
			changeVal() {
				this.$emit('changeVal')
			}
		},


	}
</script>

<style lang="scss">
	.main_title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #EEEEEE;
		height: 85rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.archives-form-item {
		display: flex;
		align-items: center;
		padding: 21rpx 0;
		border-bottom: 1rpx solid #f5f2f8;

	}

	.num_list {
		display: flex;
		align-items: center;
	}

	.num_text {
		margin-left: 250rpx;
	}
</style>